package com.ruiysoft.service.sys.redis.impl;

import com.ruiysoft.constant.ConstantKey;
import com.ruiysoft.entity.sys.SysMicroShop;
import com.ruiysoft.mapper.sys.SysMicroShopMapper;
import com.ruiysoft.service.sys.redis.IRedisSysMicroShopService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by 化增光 on 2019/1/8.
 */
@Service
public class RedisSysMicroShopServiceImpl implements IRedisSysMicroShopService {

    @Resource
    private RedisTemplate<String,SysMicroShop> shopRedisTemplate;

    @Resource
    private RedisTemplate<String,Long> idRedisTemplate;

    @Resource
    SysMicroShopMapper sysMicroShopMapper;

    @Override
    public SysMicroShop selectSysMicroShopById(Long shopId) {
        SysMicroShop shop = shopRedisTemplate.opsForValue().get(ConstantKey.SYS_MICRO_SHOP_ID_KEY+shopId);
        if (null == shop){
            shop = sysMicroShopMapper.selectById(shopId);
            if (null != shop){
                shopRedisTemplate.opsForValue().set(ConstantKey.SYS_MICRO_SHOP_ID_KEY+shopId,shop);
            }
        }
        return shop;
    }

    @Override
    public void clearSysMicroShopById(Long shopId) {
        shopRedisTemplate.delete(ConstantKey.SYS_MICRO_SHOP_ID_KEY+shopId);
    }
}
